import { request } from "@/utils/service"
import type * as Login from "./types/login"
import { getRefreshToken } from "@/utils/cache/cookies"
import { url } from "inspector"

/** 获取登录验证码 */
export function getLoginCodeApi() {
  return request<Login.LoginCodeResponseData>({
    url: "login/code",
    method: "get"
  })
}

/** 登录并返回 Token */
export function loginApi(data: Login.LoginRequestData) {
  return request<Login.LoginResponseData>({
    url: "user/login",
    method: "post",
    data
  })
}

/** 获取用户详情 */
export function getUserInfoApi() {
  return request<Login.UserInfoResponseData>({
    url: "user",
    method: "get"
  })
}

/** 刷新用户Token详情 */
export function refreshTokenApi() {
  return request<Login.RefreshTokenResponseData>({
    url: "user/refresh_token",
    method: "post",
    // 修改headers中的authorization为refresh token
    headers: Object.assign({ Authorization: `Bearer ${getRefreshToken()}` })
  })
}

/**修改企业预警通绑定情况 */
export function updateBindStatus(status: boolean) {
  return request({
    url: "user/quser",
    method: "post",
    data: { hasQUser: status }
  })
}
